<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    省：<select name="sheng" id="sheng"></select>
    市：<select name="shi" id="shi"></select>
    县：<select name="xian" id="xian"></select>
</body>
</html>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src="./sendAjax.js"></script>
<script>
    
    //加载下拉列表函数
    fn(0,"#sheng");
    async function fn(id,ele){
        let a = await sendAjax({url:"HTTP://192.168.50.70/api.php?id=" + id});
        // console.log(a);
        let str = "<option>请选择</option>";
        for(let item of a.data){
            str += `<option data-id=${item.id}>${item.name}</option>`
        }
        $(ele).html(str);
    }
    //加载市下拉列表
    $("#sheng").on("change",async ()=>{
        fn($("#sheng option:checked").attr("data-id"),"#shi");
    })
    //加载县下拉列表
    $("#shi").on("change",async ()=>{
        fn($("#shi option:checked").attr("data-id"),"#xian");
    })

    

</script>